package com.zss.servlet;

import com.zss.service.ProductService;
import com.zss.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/delProduct")
public class DelProductServlet extends HttpServlet {
    private ProductService productService=new ProductServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");
        long id = Long.parseLong(req.getParameter("id"));
        boolean b = productService.delProduct(id);
        if (b){
            resp.getWriter().print("<script>alert('删除成功!');window.location.href='/index.jsp';</script>");
        }else {
            resp.getWriter().print("<script>alert('删除失败!');window.location.href='/delProduct.jsp';</script>");
        }
    }
}
